{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "HybridNets - tutorial.ipynb",
      "provenance": [],
      "collapsed_sections": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "SO7I9ozfFpmW",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "837dcb59-18ff-48d5-8364-babc3bc41f73"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Reading package lists... Done\n",
            "Building dependency tree       \n",
            "Reading state information... Done\n",
            "libsm6 is already the newest version (2:1.2.2-1).\n",
            "libxext6 is already the newest version (2:1.3.3-1).\n",
            "git is already the newest version (1:2.17.1-1ubuntu0.9).\n",
            "unzip is already the newest version (6.0-21ubuntu1.1).\n",
            "wget is already the newest version (1.19.4-1ubuntu2.2).\n",
            "ffmpeg is already the newest version (7:3.4.8-0ubuntu0.2).\n",
            "0 upgraded, 0 newly installed, 0 to remove and 39 not upgraded.\n"
          ]
        }
      ],
      "source": [
        "!apt-get install git unzip wget ffmpeg libsm6 libxext6 -y"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "raaxWl2_RdIC",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "e177dc6d-b856-41da-b848-441a835430f6"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Requirement already satisfied: gdown in /usr/local/lib/python3.7/dist-packages (4.2.2)\n",
            "Collecting gdown\n",
            "  Downloading gdown-4.4.0.tar.gz (14 kB)\n",
            "  Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n",
            "  Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n",
            "    Preparing wheel metadata ... \u001b[?25l\u001b[?25hdone\n",
            "Requirement already satisfied: albumentations in /usr/local/lib/python3.7/dist-packages (0.1.12)\n",
            "Collecting albumentations\n",
            "  Downloading albumentations-1.1.0-py3-none-any.whl (102 kB)\n",
            "\u001b[K     |████████████████████████████████| 102 kB 12.0 MB/s \n",
            "\u001b[?25hRequirement already satisfied: opencv-python in /usr/local/lib/python3.7/dist-packages (4.1.2.30)\n",
            "Collecting opencv-python\n",
            "  Downloading opencv_python-4.5.5.64-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (60.5 MB)\n",
            "\u001b[K     |████████████████████████████████| 60.5 MB 1.2 MB/s \n",
            "\u001b[?25hRequirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from gdown) (1.15.0)\n",
            "Requirement already satisfied: filelock in /usr/local/lib/python3.7/dist-packages (from gdown) (3.6.0)\n",
            "Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (from gdown) (4.63.0)\n",
            "Requirement already satisfied: beautifulsoup4 in /usr/local/lib/python3.7/dist-packages (from gdown) (4.6.3)\n",
            "Requirement already satisfied: requests[socks] in /usr/local/lib/python3.7/dist-packages (from gdown) (2.23.0)\n",
            "Collecting opencv-python-headless>=4.1.1\n",
            "  Downloading opencv_python_headless-4.5.5.64-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (47.8 MB)\n",
            "\u001b[K     |████████████████████████████████| 47.8 MB 1.3 MB/s \n",
            "\u001b[?25hRequirement already satisfied: PyYAML in /usr/local/lib/python3.7/dist-packages (from albumentations) (3.13)\n",
            "Requirement already satisfied: scipy in /usr/local/lib/python3.7/dist-packages (from albumentations) (1.4.1)\n",
            "Collecting qudida>=0.0.4\n",
            "  Downloading qudida-0.0.4-py3-none-any.whl (3.5 kB)\n",
            "Requirement already satisfied: scikit-image>=0.16.1 in /usr/local/lib/python3.7/dist-packages (from albumentations) (0.18.3)\n",
            "Requirement already satisfied: numpy>=1.11.1 in /usr/local/lib/python3.7/dist-packages (from albumentations) (1.21.5)\n",
            "Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from qudida>=0.0.4->albumentations) (3.10.0.2)\n",
            "Requirement already satisfied: scikit-learn>=0.19.1 in /usr/local/lib/python3.7/dist-packages (from qudida>=0.0.4->albumentations) (1.0.2)\n",
            "Requirement already satisfied: matplotlib!=3.0.0,>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from scikit-image>=0.16.1->albumentations) (3.2.2)\n",
            "Requirement already satisfied: tifffile>=2019.7.26 in /usr/local/lib/python3.7/dist-packages (from scikit-image>=0.16.1->albumentations) (2021.11.2)\n",
            "Requirement already satisfied: networkx>=2.0 in /usr/local/lib/python3.7/dist-packages (from scikit-image>=0.16.1->albumentations) (2.6.3)\n",
            "Requirement already satisfied: pillow!=7.1.0,!=7.1.1,>=4.3.0 in /usr/local/lib/python3.7/dist-packages (from scikit-image>=0.16.1->albumentations) (7.1.2)\n",
            "Requirement already satisfied: PyWavelets>=1.1.1 in /usr/local/lib/python3.7/dist-packages (from scikit-image>=0.16.1->albumentations) (1.2.0)\n",
            "Requirement already satisfied: imageio>=2.3.0 in /usr/local/lib/python3.7/dist-packages (from scikit-image>=0.16.1->albumentations) (2.4.1)\n",
            "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib!=3.0.0,>=2.0.0->scikit-image>=0.16.1->albumentations) (0.11.0)\n",
            "Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib!=3.0.0,>=2.0.0->scikit-image>=0.16.1->albumentations) (2.8.2)\n",
            "Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib!=3.0.0,>=2.0.0->scikit-image>=0.16.1->albumentations) (3.0.7)\n",
            "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib!=3.0.0,>=2.0.0->scikit-image>=0.16.1->albumentations) (1.3.2)\n",
            "Requirement already satisfied: joblib>=0.11 in /usr/local/lib/python3.7/dist-packages (from scikit-learn>=0.19.1->qudida>=0.0.4->albumentations) (1.1.0)\n",
            "Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from scikit-learn>=0.19.1->qudida>=0.0.4->albumentations) (3.1.0)\n",
            "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests[socks]->gdown) (1.24.3)\n",
            "Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests[socks]->gdown) (3.0.4)\n",
            "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests[socks]->gdown) (2021.10.8)\n",
            "Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests[socks]->gdown) (2.10)\n",
            "Requirement already satisfied: PySocks!=1.5.7,>=1.5.6 in /usr/local/lib/python3.7/dist-packages (from requests[socks]->gdown) (1.7.1)\n",
            "Building wheels for collected packages: gdown\n",
            "  Building wheel for gdown (PEP 517) ... \u001b[?25l\u001b[?25hdone\n",
            "  Created wheel for gdown: filename=gdown-4.4.0-py3-none-any.whl size=14774 sha256=15edc08b7eea27445079707d4a90259cf8e051f6c756eeda39414200b7c68447\n",
            "  Stored in directory: /tmp/pip-ephem-wheel-cache-gco8h3g4/wheels/fb/c3/0e/c4d8ff8bfcb0461afff199471449f642179b74968c15b7a69c\n",
            "Successfully built gdown\n",
            "Installing collected packages: opencv-python-headless, qudida, opencv-python, gdown, albumentations\n",
            "  Attempting uninstall: opencv-python\n",
            "    Found existing installation: opencv-python 4.1.2.30\n",
            "    Uninstalling opencv-python-4.1.2.30:\n",
            "      Successfully uninstalled opencv-python-4.1.2.30\n",
            "  Attempting uninstall: gdown\n",
            "    Found existing installation: gdown 4.2.2\n",
            "    Uninstalling gdown-4.2.2:\n",
            "      Successfully uninstalled gdown-4.2.2\n",
            "  Attempting uninstall: albumentations\n",
            "    Found existing installation: albumentations 0.1.12\n",
            "    Uninstalling albumentations-0.1.12:\n",
            "      Successfully uninstalled albumentations-0.1.12\n",
            "Successfully installed albumentations-1.1.0 gdown-4.4.0 opencv-python-4.5.5.64 opencv-python-headless-4.5.5.64 qudida-0.0.4\n"
          ]
        }
      ],
      "source": [
        "!pip install --upgrade --no-cache-dir gdown albumentations opencv-python"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "aIKLQm7qRvef",
        "outputId": "92edf93c-3222-45f9-c18c-4b968864f998"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Cloning into 'HybridNets'...\n",
            "remote: Enumerating objects: 822, done.\u001b[K\n",
            "remote: Counting objects: 100% (822/822), done.\u001b[K\n",
            "remote: Compressing objects: 100% (669/669), done.\u001b[K\n",
            "remote: Total 822 (delta 445), reused 399 (delta 140), pack-reused 0\u001b[K\n",
            "Receiving objects: 100% (822/822), 184.83 MiB | 15.60 MiB/s, done.\n",
            "Resolving deltas: 100% (445/445), done.\n"
          ]
        }
      ],
      "source": [
        "!git clone https://github.com/datvuthanh/HybridNets.git"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "%cd HybridNets"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "CQ2zFwF4uOqI",
        "outputId": "953420eb-ffca-413a-c3e9-3252272b13fd"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "/content/HybridNets\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "!pip install -r requirements.txt"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "P9NtSpRkvmKo",
        "outputId": "7593c643-0430-4f8e-e163-3008e93f7e97"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Requirement already satisfied: albumentations>=1.1.0 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 1)) (1.1.0)\n",
            "Collecting efficientnet_pytorch>=0.7.1\n",
            "  Downloading efficientnet_pytorch-0.7.1.tar.gz (21 kB)\n",
            "Requirement already satisfied: matplotlib>=3.2.2 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 3)) (3.2.2)\n",
            "Requirement already satisfied: numpy>=1.21.2 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 4)) (1.21.5)\n",
            "Requirement already satisfied: opencv_python_headless>=4.5.5.62 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 5)) (4.5.5.64)\n",
            "Requirement already satisfied: prefetch_generator>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 6)) (1.0.1)\n",
            "Collecting pretrainedmodels>=0.7.4\n",
            "  Downloading pretrainedmodels-0.7.4.tar.gz (58 kB)\n",
            "\u001b[K     |████████████████████████████████| 58 kB 4.4 MB/s \n",
            "\u001b[?25hRequirement already satisfied: PyYAML>=3.13 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 8)) (3.13)\n",
            "Requirement already satisfied: scipy>=1.4.1 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 9)) (1.4.1)\n",
            "Requirement already satisfied: seaborn>=0.11.2 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 10)) (0.11.2)\n",
            "Collecting tensorboardX>=2.4.1\n",
            "  Downloading tensorboardX-2.5-py2.py3-none-any.whl (125 kB)\n",
            "\u001b[K     |████████████████████████████████| 125 kB 25.1 MB/s \n",
            "\u001b[?25hCollecting timm>=0.5.4\n",
            "  Downloading timm-0.5.4-py3-none-any.whl (431 kB)\n",
            "\u001b[K     |████████████████████████████████| 431 kB 49.5 MB/s \n",
            "\u001b[?25hRequirement already satisfied: torch>=1.10.0 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 13)) (1.10.0+cu111)\n",
            "Requirement already satisfied: torchvision>=0.11.0 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 14)) (0.11.1+cu111)\n",
            "Requirement already satisfied: tqdm>=4.61.2 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 15)) (4.63.0)\n",
            "Collecting webcolors>=1.11.1\n",
            "  Downloading webcolors-1.11.1-py3-none-any.whl (9.9 kB)\n",
            "Requirement already satisfied: qudida>=0.0.4 in /usr/local/lib/python3.7/dist-packages (from albumentations>=1.1.0->-r requirements.txt (line 1)) (0.0.4)\n",
            "Requirement already satisfied: scikit-image>=0.16.1 in /usr/local/lib/python3.7/dist-packages (from albumentations>=1.1.0->-r requirements.txt (line 1)) (0.18.3)\n",
            "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib>=3.2.2->-r requirements.txt (line 3)) (0.11.0)\n",
            "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib>=3.2.2->-r requirements.txt (line 3)) (1.3.2)\n",
            "Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib>=3.2.2->-r requirements.txt (line 3)) (3.0.7)\n",
            "Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib>=3.2.2->-r requirements.txt (line 3)) (2.8.2)\n",
            "Collecting munch\n",
            "  Downloading munch-2.5.0-py2.py3-none-any.whl (10 kB)\n",
            "Requirement already satisfied: pandas>=0.23 in /usr/local/lib/python3.7/dist-packages (from seaborn>=0.11.2->-r requirements.txt (line 10)) (1.3.5)\n",
            "Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from tensorboardX>=2.4.1->-r requirements.txt (line 11)) (1.15.0)\n",
            "Requirement already satisfied: protobuf>=3.8.0 in /usr/local/lib/python3.7/dist-packages (from tensorboardX>=2.4.1->-r requirements.txt (line 11)) (3.17.3)\n",
            "Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from torch>=1.10.0->-r requirements.txt (line 13)) (3.10.0.2)\n",
            "Requirement already satisfied: pillow!=8.3.0,>=5.3.0 in /usr/local/lib/python3.7/dist-packages (from torchvision>=0.11.0->-r requirements.txt (line 14)) (7.1.2)\n",
            "Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.7/dist-packages (from pandas>=0.23->seaborn>=0.11.2->-r requirements.txt (line 10)) (2018.9)\n",
            "Requirement already satisfied: scikit-learn>=0.19.1 in /usr/local/lib/python3.7/dist-packages (from qudida>=0.0.4->albumentations>=1.1.0->-r requirements.txt (line 1)) (1.0.2)\n",
            "Requirement already satisfied: PyWavelets>=1.1.1 in /usr/local/lib/python3.7/dist-packages (from scikit-image>=0.16.1->albumentations>=1.1.0->-r requirements.txt (line 1)) (1.2.0)\n",
            "Requirement already satisfied: networkx>=2.0 in /usr/local/lib/python3.7/dist-packages (from scikit-image>=0.16.1->albumentations>=1.1.0->-r requirements.txt (line 1)) (2.6.3)\n",
            "Requirement already satisfied: tifffile>=2019.7.26 in /usr/local/lib/python3.7/dist-packages (from scikit-image>=0.16.1->albumentations>=1.1.0->-r requirements.txt (line 1)) (2021.11.2)\n",
            "Requirement already satisfied: imageio>=2.3.0 in /usr/local/lib/python3.7/dist-packages (from scikit-image>=0.16.1->albumentations>=1.1.0->-r requirements.txt (line 1)) (2.4.1)\n",
            "Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from scikit-learn>=0.19.1->qudida>=0.0.4->albumentations>=1.1.0->-r requirements.txt (line 1)) (3.1.0)\n",
            "Requirement already satisfied: joblib>=0.11 in /usr/local/lib/python3.7/dist-packages (from scikit-learn>=0.19.1->qudida>=0.0.4->albumentations>=1.1.0->-r requirements.txt (line 1)) (1.1.0)\n",
            "Building wheels for collected packages: efficientnet-pytorch, pretrainedmodels\n",
            "  Building wheel for efficientnet-pytorch (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "  Created wheel for efficientnet-pytorch: filename=efficientnet_pytorch-0.7.1-py3-none-any.whl size=16446 sha256=eb4c7dace96c88b334d9e190e5a4ca03557283590e7502bf75bfbf8260325a05\n",
            "  Stored in directory: /root/.cache/pip/wheels/0e/cc/b2/49e74588263573ff778da58cc99b9c6349b496636a7e165be6\n",
            "  Building wheel for pretrainedmodels (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "  Created wheel for pretrainedmodels: filename=pretrainedmodels-0.7.4-py3-none-any.whl size=60965 sha256=355f24973fc01969d0f025fe37bd42d7f01d45ef4d044584312c98ad6bbef322\n",
            "  Stored in directory: /root/.cache/pip/wheels/ed/27/e8/9543d42de2740d3544db96aefef63bda3f2c1761b3334f4873\n",
            "Successfully built efficientnet-pytorch pretrainedmodels\n",
            "Installing collected packages: munch, webcolors, timm, tensorboardX, pretrainedmodels, efficientnet-pytorch\n",
            "Successfully installed efficientnet-pytorch-0.7.1 munch-2.5.0 pretrainedmodels-0.7.4 tensorboardX-2.5 timm-0.5.4 webcolors-1.11.1\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "FSQW832pRnl6",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "8cf4bde0-3f9d-416f-e34a-700fe9cc3f25"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Downloading...\n",
            "From: https://drive.google.com/uc?id=1-wbnw9_71KM9RW2f7LX9Dva6YT5vRHOF\n",
            "To: /content/HybridNets/datasets.zip\n",
            "100% 4.64G/4.64G [00:21<00:00, 211MB/s]\n",
            "Downloading...\n",
            "From: https://drive.google.com/uc?id=19CEnZzgLXNNYh1wCvUlNi8UfiBkxVRH0\n",
            "To: /content/HybridNets/det_annotations.zip\n",
            "100% 156M/156M [00:00<00:00, 187MB/s]\n",
            "Downloading...\n",
            "From: https://drive.google.com/uc?id=1NZM-xqJJYZ3bADgLCdrFOa5Vlen3JlkZ\n",
            "To: /content/HybridNets/da_seg_annotations.zip\n",
            "100% 336M/336M [00:01<00:00, 221MB/s]\n",
            "Downloading...\n",
            "From: https://drive.google.com/uc?id=1o-XpIvHJq0TVUrwlwiMGzwP1CtFsfQ6t\n",
            "To: /content/HybridNets/ll_seg_annotations.zip\n",
            "100% 260M/260M [00:03<00:00, 79.1MB/s]\n"
          ]
        }
      ],
      "source": [
        "!gdown 1-wbnw9_71KM9RW2f7LX9Dva6YT5vRHOF\n",
        "!gdown 19CEnZzgLXNNYh1wCvUlNi8UfiBkxVRH0\n",
        "!gdown 1NZM-xqJJYZ3bADgLCdrFOa5Vlen3JlkZ\n",
        "!gdown 1o-XpIvHJq0TVUrwlwiMGzwP1CtFsfQ6t"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "UQNE1je5R6nF"
      },
      "outputs": [],
      "source": [
        "!unzip -q -o datasets.zip\n",
        "!unzip -q da_seg_annotations.zip -d datasets\n",
        "!unzip -q det_annotations.zip -d datasets\n",
        "!unzip -q ll_seg_annotations.zip -d datasets"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "Mah2CWE3SRvJ",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "58bc8df0-35fc-417e-8a71-78c7d86e38c4"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "mkdir: cannot create directory ‘weights’: File exists\n",
            "  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current\n",
            "                                 Dload  Upload   Total   Spent    Left  Speed\n",
            "100   653  100   653    0     0   3863      0 --:--:-- --:--:-- --:--:--  3841\n",
            "100 52.1M  100 52.1M    0     0  14.8M      0  0:00:03  0:00:03 --:--:-- 22.1M\n"
          ]
        }
      ],
      "source": [
        "!mkdir weights\n",
        "!curl -L -o weights/hybridnets.pth https://github.com/datvuthanh/HybridNets/releases/download/v1.0/hybridnets.pth"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# set --num_gpus 0 to train on CPU\n",
        "!python train.py -p bdd100k -c 3 --batch_size 2 --num_gpus 1"
      ],
      "metadata": {
        "id": "2iDiobNJWgmw",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "db63e46f-c516-48b1-ad2f-a85907b62048"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "building database...\n",
            "100% 70000/70000 [00:49<00:00, 1408.15it/s]\n",
            "database build finish\n",
            "/usr/local/lib/python3.7/dist-packages/torch/utils/data/dataloader.py:481: UserWarning: This DataLoader will create 12 worker processes in total. Our suggested max number of worker in current system is 2, which is smaller than what this DataLoader is going to create. Please be aware that excessive worker creation might get DataLoader running slow or even freeze, lower the worker number to avoid potential slowness/freeze if necessary.\n",
            "  cpuset_checked))\n",
            "building database...\n",
            "100% 10000/10000 [00:06<00:00, 1545.20it/s]\n",
            "database build finish\n",
            "Downloading: \"https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/efficientnet-b3-5fb5a3c3.pth\" to /root/.cache/torch/hub/checkpoints/efficientnet-b3-5fb5a3c3.pth\n",
            "100% 47.1M/47.1M [00:02<00:00, 19.8MB/s]\n",
            "[Info] initializing weights...\n",
            "[Info] Successfully!!!\n",
            "Step: 428. Epoch: 0/500. Iteration: 429/35000. Cls loss: 1.04831. Reg loss: 10.80123. Seg loss: 0.59671. Total loss: 12.44624:   1% 429/35000 [05:17<7:06:09,  1.35it/s]\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Colab is going to OOM on nms_threshold 0.001, please validate on high-RAM instances\n",
        "# !python val.py -p bdd100k -c 3 -w weights/weight.pth --num_gpus 1"
      ],
      "metadata": {
        "id": "r5aPDPp5BfpX"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# set --cuda False to infer on CPU\n",
        "!python hybridnets_test.py --cuda True"
      ],
      "metadata": {
        "id": "IPJApueaBhsF",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "968b73ed-a131-4d6c-a268-3aa7caeab1ff"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "running speed test...\n",
            "test1: model inferring and postprocessing\n",
            "inferring 1 image for 10 times...\n",
            "0.2705361843109131 seconds, 3.6963632149507673 FPS, @batch_size 1\n",
            "test2: model inferring only\n",
            "inferring images for batch_size 32 for 10 times...\n",
            "2.09664990901947 seconds, 15.262443130033702 FPS, @batch_size 32\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "!python hybridnets_test_videos.py --cuda True"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "ekHKB0zcQD_Q",
        "outputId": "3d9a19ee-8af6-4f1a-eca0-7a8b1c835203"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "frame: 297\n",
            "second: 108.01905345916748\n",
            "fps: 0.3637005166975336\n"
          ]
        }
      ]
    }
  ]
}